package com.hsd.whb.service.impl;

import com.hsd.whb.entity.MeetingParticipants;
import com.hsd.whb.entity.Participants;
import com.hsd.whb.repository.MeetingParticipantsRepository;
import com.hsd.whb.service.MeetingParticipantsService;
import com.hsd.whb.service.ParticipantsService;
import com.wangjiacai.hqlQuery.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class MeetingParticipantsServiceImpl extends BaseServiceImpl implements MeetingParticipantsService {


    @Autowired
    private MeetingParticipantsRepository repository;

    @Autowired
    private ParticipantsService participantsService;


    @Override
    public MeetingParticipants findByMeetingIdAndUsername(Integer meetingId, String username) {
        Participants participants = participantsService.findParticipantsByUsername(username);
        return repository.findByMeetingIdAndParticipantsId(meetingId, participants.getId());
    }

    @Override
    public MeetingParticipants saveMeetingParticipants(Integer meetingId, String username) {
        Participants participants = participantsService.findParticipantsByUsername(username);
        MeetingParticipants meetingParticipants = repository.findByMeetingIdAndParticipantsId(meetingId, participants.getId());
        if (meetingParticipants == null) {
            meetingParticipants = new MeetingParticipants();
            meetingParticipants.setMeetingId(meetingId);
            meetingParticipants.setDeleted(0);
            meetingParticipants.setParticipantsId(participants.getId());
            return repository.save(meetingParticipants);
        }
        return meetingParticipants;
    }

    @Override
    public List<Integer> getParticipantsIdByMeetingId(Integer meetingId) {
        return repository.getParticipantsIdByMeetingId(meetingId);
    }

}
